import React, { Component } from 'react'
import PubSub from 'pubsub-js'

export default class Son extends Component {
  componentDidMount(){
    this.subId = PubSub.subscribe("money",(topic,data)=>{
      console.log(data);
    })
  }
  componentWillUnmount(){
    PubSub.unsubscribe(this.subId)
  }

  render() {
    return (
      <div>
        <h1>Son</h1>
        <button onClick={()=>{PubSub.publish("cat","小猫咪")}}>小猫咪</button>
      </div>
    )
  }
}
